package org.come.control;

import org.come.action.FromServerAction;
import org.come.action.MapAction;
import org.come.socket.GameClient;
import org.come.socket.SendMessageUntil;

import org.come.test.Main;

/**
 * 
 * @author 黄建彬
 * @date 确定版本号
 */
public class VersionControl implements FromServerAction {
	public static boolean versionFlag = false;

	@Override
	public void controlMessFromServer(String mes, String type) {
//	    String[] mesArr = mes.split("&");
//      if(Util.getTime() == 0){
//          Util.uptime(mesArr[0]);
//      }
//      Util.uptime(mesArr[0]);
//        mes = mesArr[2];
		try {
			if (!mes.startsWith(GameClient.VERSION)) {
				/** zrikka 2020 0414 */
				try {
					MapAction.flagAction.put(SendMessageUntil.accServerKey, false);
					MapAction.nettyAction.get(SendMessageUntil.accServerKey).channel().close();
					MapAction.nettyAction.put(SendMessageUntil.accServerKey, null);
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					// 版本号不一致//关闭所有面板
					if (Main.frame == null || Main.frame.getLoginJpanel() == null || Main.frame.getLoginJpanel().getLoginView() == null) {
						try {
							Thread.sleep(1000);
						} catch (Exception e) {
						}
					}
					Main.frame.getLoginJpanel().getLoginView().setMsg("您的版本号不一致，请更新版本!!");
					Thread.sleep(5000);
					System.exit(0);
				}
				/*****/
			} else if (!mes.equals(GameClient.VERSION)) {
			   
				mes = mes.substring(GameClient.VERSION.length());
				String[] vs = mes.split("\\|");
				for (int i = 0; i < vs.length; i++) {
					if (vs[i].startsWith("L")) {
						GameClient.lianhua = Integer.parseInt(vs[i].substring(1));
					} else {
						// final String string = vs[i];
						// new Thread(new Runnable() {
						// @Override
						// public void run() {
						// CreatMenuTree.downFileResult(string);
						// }
						// }).start();
					}
				}

				versionFlag = true;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
